﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web;
using System.Web.SessionState;
namespace Caifu.Fx
{
    public class BasePage : Page
    {
        protected Int32 MAXREQUEST = 3;

        protected Int32 PostCount
        {
            get
            {
                Int32 conunt = 0;
                if (Session["POSTCOUNT"] != null)
                {
                    Int32.TryParse(Session["POSTCOUNT"].ToString(), out conunt);
                }
                return conunt;
            }
            set
            {
                Session["POSTCOUNT"] = value;
            }
        }

        /// <summary>
        /// PV:Post Value 获取Post访问方式，表单控件的值
        /// </summary>
        /// <param name="controlName">表单控件的名称</param>
        /// <returns>表单控件的值</returns>
        public virtual String PV(String controlName)
        {
            return this.Request.Form[controlName];
        }

        /// <summary>
        /// QV:Query Value:获取Get访问时的查询参数;
        /// </summary>
        /// <param name="queryString">查询变量的名称</param>
        /// <returns></returns>
        public virtual String QV(String queryString)
        {
            return this.Request.QueryString[queryString];
        }

        /// <summary>
        /// 弹出警告消息
        /// </summary>
        /// <param name="message">消息</param>
        public  void ShowMessage(string message)
        {
            message = "alert('" + message + "');";
            this.ClientScript.RegisterStartupScript(this.GetType(),
                Guid.NewGuid().ToString(), message, true);
        }


        /// <summary>
        /// 调用前段JS脚本
        /// </summary>
        /// <param name="function">js函数名称</param>
        public  void CallScript(String function)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(),
            Guid.NewGuid().ToString(), function, true);
        }
    }

    /// <summary>
    /// HTTP 一般处理程序
    /// </summary>
    public class BaseHandler : IHttpHandler
    {
        protected HttpRequest Request;
        protected HttpResponse Response;
        protected HttpSessionState Session;

        protected Int32 MAXREQUEST = 2;
        protected Int32 PostCount
        {
            get
            {
                Int32 conunt = 0;
                if (Session["POSTCOUNT"] != null)
                {
                    Int32.TryParse(Session["POSTCOUNT"].ToString(), out conunt);
                }
                return conunt;
            }
            set
            {
                Session["POSTCOUNT"] = value;
            }
        }

        /// <summary>
        /// PV:Post Value 获取Post访问方式，表单控件的值
        /// </summary>
        /// <param name="controlName">表单控件的名称</param>
        /// <returns>表单控件的值</returns>
        public virtual String PV(String controlName)
        {
            return this.Request.Form[controlName];
        }

        /// <summary>
        /// QV:Query Value:获取Get访问时的查询参数;
        /// </summary>
        /// <param name="queryString">查询变量的名称</param>
        /// <returns></returns>
        public virtual String QV(String queryString)
        {
            return this.Request.QueryString[queryString];
        }

        public virtual bool IsReusable
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// 请求开始过程
        /// </summary>
        /// <param name="context">Http上下文</param>
        public virtual void ProcessRequest(HttpContext context)
        {
            //通过HTTP上下文初始化若干HTTP处理对象         
            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
        }
    }
}
